package copyengine.network.roomStructure.subMediator
{
	import copyengine.network.roomStructure.CENetworkCommandNotification;
	import copyengine.network.roomStructure.data.CENetworkRoomMediatorWhiteBoard;
	import copyengine.network.roomStructure.executeLayer.CENetworkRoomExecuteHandleNotification;
	import copyengine.utils.debug.CELog;

	import flash.events.Event;

	import org.puremvc.as3.interfaces.INotification;

	public final class CENetworkRoomSubErrorHandleMediator extends CENetworkRoomSubMediatorBasic
	{
		public function CENetworkRoomSubErrorHandleMediator(_whiteBoard:CENetworkRoomMediatorWhiteBoard)
		{
			super(_whiteBoard);
		}

		override public function listNotificationInterests():Array
		{
			return [
				CENetworkRoomExecuteHandleNotification.NOTIFICATION_SYSTEM_CATCH_AN_ERROR,
				];
		}

		override public function handleNotification(notification:INotification):void
		{
			switch (notification.getName())
			{
				case CENetworkRoomExecuteHandleNotification.NOTIFICATION_SYSTEM_CATCH_AN_ERROR:
					onCatchAnSystemError(notification.getBody());
					break;
			}
		}

		private function onCatchAnSystemError(_arg:Object):void
		{
			var errorType:String = _arg["errorType"];
			var error:Event = _arg["error"];
			if (errorType == CENetworkRoomExecuteHandleNotification.ERROR_TYPE_SOCKET_CHANEL)
			{
				//异常错误CleanWhiteBoard
				whiteBoard.clean();

				//发送错误
				sendNotification(CENetworkCommandNotification.SEND_UNEXPECTED_DISCONNECT);
			}
			else if (errorType == CENetworkRoomExecuteHandleNotification.ERROR_TYPE_RTMFP_CHANEL)
			{
				//Rtmfp作为辅助Chanel,出现问题不影响主程序运行
			}
			CELog.err("CENetworkRoomSubErrorHandleMediator->onCatchAnSystemError catch an error:");
			CELog.err(error.toString());

		}

	}
}
